
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller.commands;

import controller.StoreFactory;
import core.Node;
import java.util.logging.Level;
import java.util.logging.Logger;
import load.storage.StoreIO;
import model.graphic.objects.GNode;

/**
 *
 * @author Jelle
 */
public class EditStoreCommand extends BasicCommand{
    private GNode node;
    private String type;

    public EditStoreCommand(GNode node, String type){
        this.type=type;
        this.node=node;
    }

    @Override
    public void execute() {
       
        Node n = sync.get(node);
        StoreIO st = (StoreIO)n;
        try {
            Class cl = Class.forName(type);
            if(Integer.class.isAssignableFrom(cl)){
                st.setType(StoreFactory.DEFAULT_INT);
                node.setValue(StoreFactory.DEFAULT_INT.toString());
            } else if(Boolean.class.isAssignableFrom(cl)){
                st.setType(StoreFactory.DEFAULT_BOOLEAN);
                node.setValue(StoreFactory.DEFAULT_BOOLEAN.toString());
            } else if(String.class.isAssignableFrom(cl)){
                st.setType(StoreFactory.DEFAULT_STRING);
                node.setValue(StoreFactory.DEFAULT_STRING);
            } else if(Double.class.isAssignableFrom(cl)){
                st.setType(StoreFactory.DEFAULT_DOUBLE);
                node.setValue(StoreFactory.DEFAULT_DOUBLE.toString());
            }  else if(Object.class.isAssignableFrom(cl)){
                st.setType(new Object());
                node.setValue("");
            }
    
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(EditStoreCommand.class.getName()).log(Level.SEVERE, null, ex);
        }
        node.setType("StoreIO<"+type.substring(10, type.length())+">");

        gmodel.setModelChanged();
        gview.repaint();
    }


}
